<template>
	<view class="mainpadding_top" style="padding-bottom: 150rpx;">
		<view class="chatItemMessage" @click="jumperurl('/pages_message/systemnews')">
			<view class="imageBox">
				<image src="@/static/image/system/xitong.png" mode="">
				</image>
			</view>
			<view class="flexbetween" style="width: 100%;">
				<view class="right">
					<view class="nameTime">
						<view class="flexleft">
							<view class="name">系统消息</view>
							<view class="number xiankuan" v-if="userInfo.xtnews_noread_num">
								{{userInfo.xtnews_noread_num}}</view>
						</view>
					</view>
					<view class="bottom xiankuan" v-if="userInfo.xtnews">{{userInfo.xtnews.title}}</view>
				</view>
				<u-icon name="arrow-right" size="16" color="#999"></u-icon>
			</view>
		</view>
		<view class="chatItemMessage" @click="jumperurl('/pages_message/hudongnews')">
			<view class="imageBox">
				<image src="@/static/image/system/hudong.png" mode="">
				</image>
			</view>
			<view class="flexbetween" style="width: 100%;">
				<view class="right">
					<view class="nameTime">
						<view class="flexleft">
							<view class="name">互动消息</view>
							<view class="number" v-if="userInfo.hdrecord_noread_num">{{userInfo.hdrecord_noread_num}}
							</view>
						</view>
					</view>
					<view class="bottom xiankuan" v-if="userInfo.hdrecord">{{userInfo.hdrecord.memo}}</view>
				</view>
				<u-icon name="arrow-right" size="16" color="#999"></u-icon>
			</view>
		</view>
		<uni-swipe-action>
			<uni-swipe-action-item :right-options="options" @click="onClick(item,index)" v-for="(item,index) in chatList" :key="item.id">
				<view class="chatItemMessage" @click.stop="enterchat(item)">
					<view class="imageBox">
						<image :src="item.firend.avatar_text" mode="">
						</image>
					</view>
					<view class="right">
						<view class="nameTime">
							<view class="flexleft">
								<view class="name">{{item.userbz?item.userbz.bz:item.firend.nickname}}</view>
								<view class="number" v-if="item.noread_num">{{item.noread_num}}</view>
							</view>
							<view class="time margin_right3" v-if="item.new_content">{{item.new_content.createtime_text}}</view>
						</view>
						<template v-if="item.new_content">
							<view class="bottom yihang" v-if="item.new_content.data_type==1">
								{{item.new_content.message}}</view>
							<view class="bottom yihang" v-if="item.new_content.data_type==2">[图片]</view>
							<view class="bottom yihang" v-if="item.new_content.data_type==3">[视频]</view>
							<view class="bottom yihang" v-if="item.new_content.data_type==4">[分享视频]</view>
							<view class="bottom yihang" v-if="item.new_content.data_type==5">[动态]</view>
							<view class="bottom yihang" v-if="item.new_content.data_type==6">[视频通话]</view>
							<view class="bottom yihang" v-if="item.new_content.data_type==7">[语音通话]</view>
						</template>
					</view>
				</view>
			</uni-swipe-action-item>
		</uni-swipe-action>

		<tabbardi ref="tabbardiref" :current="3"></tabbardi>
	</view>
</template>

<script>
	// import WebSocket from '@/static/websocket.js' //websocket封装
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				 options:[ {
				            text: '删除',
				            style: {
				                backgroundColor: '#ff526a'
				            }
				        }
				      ],
				user_id: "",
				chatList: [],
				// websocket: null,
				userInfo: {}
			}
		},
		onLoad() {
			uni.hideTabBar()
			uni.$on("updatechatFnteList", data => {
				console.log("触发方法了会话列表哈哈哈");
				this.init()
				// this.$refs.tabbardiref.getnoreadNum()
			})
		},
		onUnload() {
			uni.$off('updatechatFnteList')
		},
		onShow() {
			setTimeout(() => {
				this.$refs.tabbardiref.noreadNum = 0
				this.$refs.tabbardiref.getnoreadNum()
			}, 100)
			// console.log(uni.getStorageSync("token"),">>>>>>>>>>>>>>>>>>");
			this.user_id = uni.getStorageSync("user_id")
			this.init()
			this.getuserinfo()
		},
		methods: {
			onClick(item,index){
				console.log(item);
				this.chatList.splice(index,1)
				this.delitemchat(item)
			},
			jumperurl(url) {
				uni.navigateTo({
					url
				})
			},
			delitemchat(item){
				httpRequest.request('/api/user/delChatHy', 'GET', {id:item.id}).then(res => {
					this.$refs.tabbardiref.getnoreadNum()
				})
			},
			getuserinfo() {
				httpRequest.request('/api/user/index', 'GET', {}).then(res => {
					this.userInfo = res.data
				})
			},
			init() {
				httpRequest.request('/api/user/getChatList', 'GET', {}).then(res => {
					this.chatList = res.data
				})
			},
			enterchat(item) { //进入聊天
				// uni.navigateTo({
				// 	url: '/pages_message/popup'
				// })
				// return false
				let data = {
					firend_id: item.firend_id,
					friend_name: item.firend.nickname,
					firend_avatar_text: item.firend.avatar_text
				}
				uni.navigateTo({
					url: "/pages_message/chat?msg=" + encodeURIComponent(JSON.stringify(data))
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.yihang {
		width: 300rpx;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.content {
		padding-bottom: 100rpx;
	}

	/deep/.u-tabs__wrapper__nav {
		background-color: #ffffff !important;
	}

	/deep/.u-tabs__wrapper__nav__item {
		flex: 1 !important;
	}

	// 聊天消息

	.chatItemMessage {
		display: flex;
		margin-bottom: 40rpx;

		.imageBox {
			width: 114rpx;
			min-width: 114rpx;
			height: 114rpx;
			border-radius: 50%;
			overflow: hidden;
			margin-right: 40rpx;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.right {
			flex: 1;
		}

		.nameTime {
			display: flex;
			justify-content: space-between;

			.name {
				font-size: 32rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 500;
				color: #000000;
				margin-right: 10rpx;
			}

			.number {
				width: 34rpx;
				height: 34rpx;
				line-height: 34rpx;
				text-align: center;
				background: #FF526A;
				border-radius: 50%;
				font-size: 20rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 500;
				color: #FFFFFF;
			}

			.time {
				font-size: 24rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 500;
				color: #666666;
			}
		}

		.bottom {
			font-size: 26rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
			color: #999999;
			margin-top: 35rpx;
		}
	}

	// 互动消息
	.interactionBox {
		background-color: rgba(250, 250, 250, 0.69);
		padding: 30rpx;
	}

	.interactionItem {
		display: flex;
		justify-content: space-between;
		margin-bottom: 40rpx;
		padding: 30rpx;
		background-color: #ffffff;

		.left {
			display: flex;
		}

		.imageBox {
			width: 114rpx;
			height: 114rpx;
			min-width: 114rpx;
			border-radius: 50%;
			overflow: hidden;
			margin-right: 40rpx;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.name {
			font-size: 30rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
			color: #F3271C;
		}

		.reply {
			font-size: 24rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
			color: #000000;
		}

		.time {
			font-size: 24rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
			color: #333333;
		}

		.right {
			width: 114rpx;
			height: 114rpx;
			border-radius: 15rpx 15rpx 15rpx 15rpx;
			overflow: hidden;
			display: flex;
			align-items: center;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.sanhang {
			width: 114rpx;
			height: 89rpx;
			text-overflow: -o-ellipsis-lastline;
			overflow: hidden;
			text-overflow: ellipsis;
			display: -webkit-box;
			-webkit-line-clamp: 3;
			line-clamp: 3;
			-webkit-box-orient: vertical;

			// word-break: break-all;
			// overflow: hidden;
			// text-overflow: ellipsis;
			// display: -webkit-box;
			// -webkit-line-clamp: 3;
			// -webkit-box-orient: vertical;
		}
	}

	.goodsImg {
		width: 124rpx;
		height: 124rpx;
		border-radius: 14rpx 14rpx 14rpx 14rpx;
		overflow: hidden;

		image {
			width: 100%;
			height: 100%;
		}
	}
</style>